<%= form_for [:admin, @user], url: admin_user_path(@user) do |f| %>
  <%= render "shared/error_messages", target: @user %>
  <div class="form-group">
    <%= f.label :login %>
    <%= f.text_field :login, class: "form-control" %>
  </div>

  <div class="form-group">
    <%= f.label :name %>
    <%= f.text_field :name, class: "form-control" %>
  </div>

  <div class="form-group">
    <%= f.label :email %>
    <%= f.email_field :email, class: "form-control" %>
  </div>

  <div class="form-group">
    <%= f.label :phone_number %>
    <%= f.text_field :phone_number, class: "form-control" %>
  </div>

  <% if Setting.has_profile_field? :location %>
  <div class="form-group">
    <%= f.label :location %>
    <%= f.text_field :location, class: "form-control" %>
  </div>
  <% end %>

  <% if Setting.has_module? :github %>
  <div class="form-group">
    <%= f.label :github %>
    <%= f.text_field :github, class: "form-control" %>
  </div>
  <% end %>

  <% if Setting.has_profile_field? :twitter %>
  <div class="form-group">
    <%= f.label :twitter %>
    <%= f.text_field :twitter, class: "form-control" %>
  </div>
  <% end %>

  <div class="form-group form-check">
    <%= f.check_box :email_public, class: "form-check-input" %>
    <%= f.label :email_public, class: "form-check-label" %>
  </div>

  <% if Setting.has_profile_field? :company %>
  <div class="form-group">
    <%= f.label :company %>
    <%= f.text_field :company, class: "form-control" %>
  </div>
  <% end %>

  <% if Setting.has_profile_field? :tagline %>
  <div class="form-group">
    <%= f.label :tagline %>
    <%= f.text_field :tagline, class: "form-control" %>
  </div>
  <% end %>

  <div class="form-group">
    <%= f.label :bio %>
    <%= f.text_area :bio, class: "form-control" %>
  </div>


  <% if Setting.has_profile_field? :website %>
  <div class="form-group">
    <%= f.label :website %>
    <%= f.text_field :website, class: "form-control" %>
  </div>
  <% end %>

  <div class="form-group">
    <%= f.label :avatar %>
    <%= f.file_field :avatar, class: "form-control" %>
  </div>

  <div class="form-group">
    <%= user_avatar_tag(@user, :lg) %>
  </div>

  <% if @user.user_type == :user %>
  <div class='d-flex'
      data-controller='roles-filter'
      data-roles-filter-selected-state-value='<%= @user.state_before_type_cast || "" %>'
      data-roles-filter-state-blank-value='false'
      data-roles-filter-states-info-value='<%= user_states_info.to_json %>' >
    <div class="pr-4 form-group w-100">
      <%= f.label "category", "类别" %>
      <%= select_tag(:category,
                     options_for_select([["全部类别", ""], ["个人账号", "-1--99"], ["公众号", "120--122"], ["个人公众号", "125--127"], ["企业号", "130--139"]], @user.fetch_role_category),
                     data: { "roles-filter-target" => "main", "action" => "change->roles-filter#select" }, class: "form-control") %>
    </div>

    <div class="form-group w-100">
      <%= f.label :state %>
      <%= f.select :state, "", {}, data: { "roles-filter-target" => "sub" }, class: "form-control" %>
    </div>
  </div>

    <div class="form-group">
      <%= f.label :sign_in_count %>
      <%= f.text_field :sign_in_count, class: "form-control", readonly: true %>
    </div>

    <div class="form-group">
      <%= f.label :last_sign_in_at %>
      <%= f.text_field :last_sign_in_at, class: "form-control", readonly: true %>
    </div>

    <div class="form-group">
      <%= f.label :current_sign_in_at %>
      <%= f.text_field :current_sign_in_at, class: "form-control", readonly: true %>
    </div>

    <div class="form-group">
      <%= f.label :last_sign_in_ip %>
      <%= f.text_field :last_sign_in_ip, class: "form-control", readonly: true %>
    </div>

    <div class="form-group">
      <%= f.label :current_sign_in_ip %>
      <%= f.text_field :current_sign_in_ip, class: "form-control", readonly: true %>
    </div>

    <% if @user.authorizations.any? %>
    <div class="form-group">
      <table class="table">
        <% @user.authorizations.each do |auth| %>
          <tr>
            <td style="width:100px;"><%= auth.provider %></td>
            <td><%= auth.uid %></td>
            <td><%= link_to(raw('<i class="fas fa-minus-circle"></i>'), auth_unbind_by_admin_admin_user_path( @user.id,auth.provider), rel: "twitsy", title: ("users.click_to_unbind"), method: 'delete' )%></td>
          </tr>
        <% end %>
      </table>
    </div>
    <% end %>

  <% end %>

  <div class="row">
    <div class="col-sm-6">
      <%= f.submit t("common.save"), class: "btn btn-block btn-primary", "data-disable-with" => t("common.saving") %>
    </div>
    <div class="col-sm-6">
      <% if !@user.deleted? %>
        <%= link_to "删除此用户", admin_user_path(@user.id), "data-confirm" => "警告！此动作无法撤销，确定要删除么?", method: :delete, class: "btn btn-danger" %>
      <% end %>
    </div>
  </div>
<% end %>
